class Solution:
    def minSubArrayLen(self, s: int, nums) -> int:
        if len(nums) == 0:
            return 0
        start = 0
        end = 1
        nowSum = nums[start]
        minLen = len(nums) + 1
        while end <= len(nums):
            if nowSum >= s:
                minLen = min(minLen, end - start)
                if start + 1 < end:
                    nowSum -= nums[start]
                    start = start + 1
                else:
                    if end != len(nums):
                        nowSum += nums[end]
                        end = end + 1
                    else:
                        break
            else:
                if end != len(nums):
                    nowSum += nums[end]
                    end = end + 1
                else:
                    break

        return minLen if minLen != len(nums) + 1 else 0


if __name__ == '__main__':
    so = Solution()
    s = 11
    nums = [1,2,3,4,5]
    r = so.minSubArrayLen(s, nums)
    print(r)
